<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="140px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="付款单号">
              <el-input v-model="form.paymentSn"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="审核状态">
              <el-select v-model="form.status" clearable placeholder="请选择">
                <el-option
                  v-for="item in statusOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <template>
                <el-select v-model="form.hospitalId" clearable filterable placeholder="请选择">
                  <el-option
                    v-for="item in hospitalOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="提交日期">
              <el-date-picker
                value-format="yyyy-MM-dd HH:mm:ss"
                v-model="form.dates"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            <el-button
              v-if="permissionJson.indexOf('AdminMmkHospitalPaidBackProvider.exportHospitalPaidOrders') !=-1"
              plain
              type="primary"
              class="el-icon-download"
              @click="excelEvent"
            >导出</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" width="100px"></el-table-column>
        <el-table-column prop="paymentSn" label="付款单号"></el-table-column>
        <el-table-column prop="hospitalName" label="医院名称"></el-table-column>
        <el-table-column prop="amount" label="付款单据总金额"></el-table-column>
        <!-- <el-table-column prop="paidRatio" label="回款比率"></el-table-column> -->
        <el-table-column prop="paidAmount" label="付款金额"></el-table-column>
        <el-table-column prop="paidCard" label="付款卡号"></el-table-column>
        <el-table-column prop="paidAccount" label="户名"></el-table-column>
        <el-table-column prop="createdTime" label="提交日期"></el-table-column>
        <el-table-column prop="approvedStatus" label="美美咖审核状态"></el-table-column>
        <el-table-column prop="approvedTime" label="审核通过日期"></el-table-column>
        <el-table-column prop="remark" label="备注"></el-table-column>
        <el-table-column fixed="right" label="操作" align="center">
          <template slot-scope="scope">
            <span
              v-if="permissionJson.indexOf('AdminMmkHospitalPaidBackProvider.checkHospitalPaidOrder') !=-1"
            >
              <el-button
                v-if="scope.row.approvedStatus=='待审核'"
                type="text"
                size="small"
                @click="toRoutes('checks',scope.row.id)"
              >审核</el-button>
            </span>
            <el-button
              v-if="permissionJson.indexOf('AdminMmkHospitalPaidBackProvider.getHospitalPaidOrderDetail') !=-1"
              type="text"
              size="small"
              @click="toRoutes('checkinfo',scope.row.id)"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { payList, exportfun } from "@/api/hospitalCheck";
import { hospitalList } from "@/api/financialBack";
import { downFile } from "@/filters/index";
import { exportfile } from "@/api/exporfile";
export default {
    name:"checkindex",
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      tableLoading: false,
      statusOption: [
        {
          value: "0",
          label: "待审核"
        },
        {
          value: "1",
          label: "审核通过"
        },
        {
          value: "2",
          label: "审核驳回"
        }
      ],
      hospitalOptions: [],
      form: {
        dates: [],
        paymentSn: null,
        status: null,
        hospitalId: "",
        startTime: null,
        endTime: null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 0,
      listForm: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  filters: {
    cardType: function(e) {
      return window.helper.cardType(e);
    },
    status: function(val) {
      return this.statusOption.map(item => {
        if (item.value == val) {
          return item.label;
        }
      });
    }
  },
  created() {
    this.getHospital();
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    //按钮权限
    hasPermission(e) {
      return window.helper.hasPermission(e);
    },
    //成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    //失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    //医院名称
    getHospital() {
      hospitalList().then(res => {
        //  console.log(res.data.data)
        if (res.data.data) {
          this.hospitalOptions = res.data.data.map(item => {
            return { value: item.id + "", label: item.name };
          });
        }
      });
    },
    //查询
    searchFn() {
      this.form.pageNum = 1;
      if (!this.form.hospitalId) {
        this.form.hospitalId = "";
      }
      if (!this.form.status) {
        this.form.status = null;
      }
      if (!this.form.paymentSn) {
        this.form.paymentSn = null;
      }
      if (this.form.dates) {
        this.form.startTime = this.form.dates[0];
        this.form.endTime = this.form.dates[1];
      } else {
        this.form.startTime = null;
        this.form.endTime = null;
      }

      // console.log(this.form)
      this.getList(this.form);
    },
    // 路由跳转
    toRoutes(e, userId) {
      let route = { name: e, query: { userId: userId } };
      this.$router.push(route);
    },
    //导出
    excelEvent() {
      exportfun(this.form).then(res => {
        exportfile(res);
      });
    },
    //列表数据获取
    getList(e) {
      this.tableLoading = true;
      let datas = e;
      payList(datas)
        .then(res => {
          console.log(res);
          if (res.data.code == 0) {
            this.tableData = res.data.data.paidOrderResponseDTOS;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },

    //改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    //选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>